package cate.game.stat.item;

import cate.common.table.d.GDOperation;
import cate.game.role.Role;
import cp.bi.mod.res.io.ResIo;
import cp.solution.business.stat.item.ItemIoEntity;
import easy.java.dev.note.NoteClass;

import java.util.Date;

@NoteClass(value = "统计资源产出与消耗")
public class StatItemIOEntity extends ItemIoEntity {

    public StatItemIOEntity read(Role role) {
        this.roleUid = role.getUid();
        this.roleName = role.getBase().name;
        this.roleLevel = role.getBase().level;
        this.roleVip = role.getBase().vip;
        this.srvId = role.getBase().srvId;
        this.operation = role.log.getOperation();
        this.operationSub = role.log.getOperationSub();
        this.operationDesc = GDOperation.getDesc(this.operation, this.operationSub);
        this.time = new Date();
        return this;
    }

    public ResIo toResIo() {
        ResIo r = new ResIo();
        r.roleId = this.roleUid;
        r.roleName = this.roleName;
        r.roleLevel = this.roleLevel;
        r.roleVip = this.roleVip;
        r.srvId = this.srvId;
        r.itemType = this.itemType;
        r.itemTid = this.itemTid;
        r.itemName = null;
        r.itemNameCn = this.itemName;
        r.numChange = this.itemNum;
        r.numFinal = this.itemNumEnd;
        r.opr = this.operation;
        r.oprDesc = this.operationDesc;
        r.oprNote = ""+this.operationSub;
        r.dt = this.time != null ? this.time : new Date();
        return r;
    }

}
